package com.token.iot.bratterycharging.boss.web;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import com.outstanding.framework.base.TransactionLogger;
import com.token.base.order.api.PayItemDTO;

public class PayItemStrDTO {
	//
	//name=1分钟,time=1,amount=0.01|name=2分钟,time=2,amount=0.02
	private String valueStr;

	private String id;
	
	
	
	
	
	public String getId() {
		return id;
	}




	public void setId(String id) {
		this.id = id;
	}




	public String getValueStr() {
		return valueStr;
	}




	public void setValueStr(String valueStr) {
		this.valueStr = valueStr;
	}




	public List<PayItemDTO> toPayItem(){
		List<PayItemDTO> dtos = new ArrayList();
		String[] items = valueStr.split("\\|");
		for(String str:items) {
			PayItemDTO dto = new PayItemDTO();
			//name=sdfad
			String[]  item = str.split(",");
			for(String s:item) {
				TransactionLogger.debug("这s="+s);
				String[] nameValue = s.split("=");
				if(nameValue.length ==2) {
					String name = nameValue[0];
					String value = nameValue[1];
					if("name".equalsIgnoreCase(name)) {
						dto.setName(value);
					}
					if("amount".equalsIgnoreCase(name)) {
						dto.setAmount(new BigDecimal(value));
					}
					if("time".equalsIgnoreCase(name)) {
						dto.setTime(Integer.parseInt(value));
					}
				}
			}
			dtos.add(dto);
		}
		return dtos;
	} 
	
	static public void main(String[] args) {
		PayItemStrDTO d = new PayItemStrDTO();
		d.setValueStr("name=1分钟,time=1,amount=0.01|name=2分钟,time=2,amount=0.02");
		d.toPayItem();
	}
	
}
